# THIS IMPLEMENTATION IS A TEST TO REDUCE THE NUMBER OF FFLs
# BECAUSE 1.9 MILLION SEEMED A LOT
from collections import defaultdict

INPUT = "RegulationTwoColumnTable_Documented_2013927.tsv"

data = defaultdict(set)
with open(INPUT) as inf:
    for line in inf:
        a,b = line.rstrip().split(";")
        if a!=b:
            data[a].add(b)

# find all triplets such that A -> B -> C and  A -> C
z=0
found = []
for a,bs in data.items():
    bint = bs.intersection
    for b in bs:
        if a not in data[b]:
            for c in bint(data[b]):
                if a not in data[c] and b not in data[c]:
                    found.append("{} {} {}".format(a, b, c))

print z
print len(set(found))